package org.cll.lagou.study.minicat.server;

/**
 * 描述信息:
 * Http协议工具类
 * @author CLL
 * @version 1.0
 * @date 2020/7/2 8:45
 */
public class IHttpProtocolUtil {

    /**
     * 为响应码200提供请求头信息
     * @param contentLength 响应码请求体长度
     * @return  响应码200的响应头
     */
    public static String getHttpResponseHeader200(long contentLength) {
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: " + contentLength + " \n" +
                "\r\n";
    }

    /**
     * 为响应码200提供响应头和响应体
     * @param responseText 响应体数据
     * @return  响应码200
     */
    public static String getHttpResponse200(String responseText) {
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: " + responseText.getBytes().length + " \n" +
                "\r\n" + responseText;
    }

    /**
     * 为响应码404提供响应头信息和响应体数据
     * @return  响应码404
     */
    public static String getHttpResponse404() {
        String str404 = "<h1> request 404 not found</h1>";
        return "HTTP/1.1 404 NOT FOUND \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length: " + str404.getBytes().length + " \n" +
                "\r\n" + str404;
    }
}